﻿__CreateJSPath = function (js) {
    var scripts = document.getElementsByTagName("script");
    var path = "";
    for (var i = 0, l = scripts.length; i < l; i++) {
        var src = scripts[i].src;
        if (src.indexOf(js) != -1) {
            var ss = src.split(js);
            path = ss[0];
            break;
        }
    }
    var href = location.href;
    href = href.split("#")[0];
    href = href.split("?")[0];
    var ss = href.split("/");
    ss.length = ss.length - 1;
    href = ss.join("/");
    if (path.indexOf("https:") == -1 && path.indexOf("http:") == -1 && path.indexOf("file:") == -1 && path.indexOf("\/") != 0) {
        path = href + "/" + path;
    }
    return path;
}

var bootPATH = __CreateJSPath("boot.js");

//debugger
mini_debugger = false;

//miniui
document.write('<link href="' + bootPATH + 'miniui/themes/default/miniui.css" rel="stylesheet" type="text/css" />');
document.write('<link href="' + bootPATH + 'miniui/themes/blue/skin.css" rel="stylesheet" type="text/css" />');
document.write('<link href="' + bootPATH + 'miniui/themes/icons.css" rel="stylesheet" type="text/css" />');
document.write('<link href="' + bootPATH + 'Site.css?x=' + Math.random() + '" rel="stylesheet" type="text/css" />');
document.write('<script src="' + bootPATH + 'jquery-1.6.2.min.js" type="text/javascript"></script>');
document.write('<script src="' + bootPATH + 'miniui/miniui.js" type="text/javascript" ></script>');
document.write('<script src="' + bootPATH + 'combox.js" type="text/javascript"></script>');
document.write('<script src="' + bootPATH + 'Webset.js" type="text/javascript"></script>');
document.write('<script src="' + bootPATH + 'function.js" type="text/javascript"></script>');

//skin
var skin = getCookie("miniuiSkin");
if (skin) {
    document.write('<link href="' + bootPATH + 'miniui/themes/' + skin + '/skin.css" rel="stylesheet" type="text/css" />');
}


////////////////////////////////////////////////////////////////////////////////////////
function getCookie(sName) {
    var aCookie = document.cookie.split("; ");
    var lastMatch = null;
    for (var i = 0; i < aCookie.length; i++) {
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0]) {
            lastMatch = aCrumb;
        }
    }
    if (lastMatch) {
        var v = lastMatch[1];
        if (v === undefined) return v;
        return unescape(v);
    }
    return null;
}

/* 中国电话，包括手机 */
function isTel(v) {
    var re = /((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/;

    return re.test(v);
}

/* 是否钱 */
function isMoney(v) {
    var re = /^[0-9]+(.[0-9]{1,2})?$/;
    return re.test(v);
}

/* 是网址 */
function isHref(v) {
    var strRegex = "^((https|http|ftp|rtsp|mms)?://)"
        + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@
        + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
        + "|" // 允许IP和DOMAIN（域名）
        + "([0-9a-z_!~*'()-]+\.)*" // 域名- www.
        + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名
        + "[a-z]{2,6})" // first level domain- .com or .museum
        + "(:[0-9]{1,4})?" // 端口- :80
        + "((/?)|" // a slash isn't required if there is no file name
        + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
    var re = new RegExp(strRegex);
    return re.test(v);
}

function CheckCard(cardid) {
    if (cardid != "") {
        if (cardid.length != 18) {
            return false;
        }
        else {
            var area = { 11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古", 21: "辽宁", 22: "吉林", 23: "黑龙江", 31: "上海", 32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南", 42: "湖北", 43: "湖南", 44: "广东", 45: "广西", 46: "海南", 50: "重庆", 51: "四川", 52: "贵州", 53: "云南", 54: "西藏", 61: "陕西", 62: "甘肃", 63: "青海", 64: "宁夏", 65: "新疆", 71: "台湾", 81: "香港", 82: "澳门", 91: "国外" };
            if (area[parseInt(cardid.substr(0, 2))] == null) {
                return false;
            }

            if (!/^\d{17}(\d|x|X)$/.test(cardid)) {
                return false;
            }
            else {
                var birthday = cardid.substr(6, 4) + "/" + cardid.substr(10, 2) + "/" + cardid.substr(12, 2);
                try {
                    var d = new Date(birthday);
                    //计算校验位
                    var idcard_array = new Array();
                    idcard_array = cardid.split("");
                    var S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7
                            + (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9
                            + (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10
                            + (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5
                            + (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8
                            + (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4
                            + (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2
                            + parseInt(idcard_array[7]) * 1
                            + parseInt(idcard_array[8]) * 6
                            + parseInt(idcard_array[9]) * 3;
                    var Y = S % 11;
                    var JYM = "10X98765432";
                    var M = JYM.substr(Y, 1); //判断校验位
                    if (M != idcard_array[17] && idcard_array[17] != 'x') {
                        return false;
                    }
                } catch (e) {
                    return false;
                }
            }
        }
    }
}

function onActionRenderer(e) {
    var record = e.record;
    var s = '<span class="icon-edit actionspan" title="修改" onclick="editRow(' + record._uid + ')"></span><span class="separator"></span><span class="icon-remove actionspan" title="删除" onclick="delRow(' + record._uid + ')"></span>';
    return s;
}

function onPayRenderer(e) {
    var record = e.record;
    var s = '<span class="icon-edit payspan" title="缴费" onclick="addpay(' + record._uid + ')"></span>';
    return s;
}

function onTypeRenderer(e) {
    for (var i = 0; i < Type.length; i++) {
        var t = Type[i];
        if (t.id == e.value)
            return t.text;
    }
    return "";
}

function onTelValidation(e) {
    if (e.isValid) {
        if (e.value != '') {
            if (!isTel(e.value)) {
                e.errorText = "请输入正确的电话号码";
                e.isValid = false;
            }
        }
    }
}

function onMoneyValidation(e) {
    if (e.isValid) {
        if (e.value != '') {
            if (!isMoney(e.value)) {
                e.errorText = "请输入最多2位小数的数字";
                e.isValid = false;
            }
        }
    }
}

function onHrefValidation(e) {
    if (e.isValid) {
        if (e.value != '') {
            if (!isHref(e.value)) {
                e.errorText = "请输入url";
                e.isValid = false;
            }
        }
    }
}